home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / fax / src / libtiff / tif_compress.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  5KB  |  159 lines

  1. #ifndef lint
  2. static char rcsid[] = "$Header: /usr/people/sam/tiff/libtiff/RCS/tif_compress.c,v 1.32 92/10/23 09:45:12 sam Rel $";
  3. #endif
  4.  
  5. /*
  6.  * Copyright (c) 1988, 1989, 1990, 1991, 1992 Sam Leffler
  7.  * Copyright (c) 1991, 1992 Silicon Graphics, Inc.
  8.  *
  9.  * Permission to use, copy, modify, distribute, and sell this software and 
  10.  * its documentation for any purpose is hereby granted without fee, provided
  11.  * that (i) the above copyright notices and this permission notice appear in
  12.  * all copies of the software and related documentation, and (ii) the names of
  13.  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  14.  * publicity relating to the software without the specific, prior written
  15.  * permission of Sam Leffler and Silicon Graphics.
  16.  * 
  17.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  18.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  19.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  20.  * 
  21.  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  22.  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  23.  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  24.  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
  25.  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  26.  * OF THIS SOFTWARE.
  27.  */
  28.  
  29. /*
  30.  * TIFF Library
  31.  *
  32.  * Compression Scheme Configuration Support.
  33.  */
  34. #include "tiffiop.h"
  35.  
  36. typedef struct {
  37.     char*    name;
  38.     int    scheme;
  39.     TIFFVoidMethod    init;
  40. } cscheme_t;
  41. static const cscheme_t CompressionSchemes[] = {
  42.     { "Null",        COMPRESSION_NONE,    TIFFInitDumpMode },
  43. #ifdef LZW_SUPPORT
  44.     { "LZW",        COMPRESSION_LZW,    TIFFInitLZW },
  45. #endif
  46. #ifdef PACKBITS_SUPPORT
  47.     { "PackBits",    COMPRESSION_PACKBITS,    TIFFInitPackBits },
  48. #endif
  49. #ifdef THUNDER_SUPPORT
  50.     { "ThunderScan",    COMPRESSION_THUNDERSCAN,TIFFInitThunderScan },
  51. #endif
  52. #ifdef NEXT_SUPPORT
  53.     { "NeXT",        COMPRESSION_NEXT,    TIFFInitNeXT },
  54. #endif
  55. #ifdef JPEG_SUPPORT
  56.     { "JPEG",        COMPRESSION_JPEG,    TIFFInitJPEG },
  57. #endif
  58. #ifdef CCITT_SUPPORT
  59.     { "CCITT RLE",    COMPRESSION_CCITTRLE,    TIFFInitCCITTRLE },
  60.     { "CCITT RLE/W",    COMPRESSION_CCITTRLEW,    TIFFInitCCITTRLEW },
  61.     { "CCITT Group3",    COMPRESSION_CCITTFAX3,    TIFFInitCCITTFax3 },
  62.     { "CCITT Group4",    COMPRESSION_CCITTFAX4,    TIFFInitCCITTFax4 },
  63. #endif
  64. };
  65. #define    NSCHEMES (sizeof (CompressionSchemes) / sizeof (CompressionSchemes[0]))
  66.  
  67. static const cscheme_t *
  68. DECLARE1(findScheme, int, scheme)
  69. {
  70.     register const cscheme_t *c;
  71.  
  72.     for (c = CompressionSchemes; c < &CompressionSchemes[NSCHEMES]; c++)
  73.         if (c->scheme == scheme)
  74.             return (c);
  75.     return ((const cscheme_t *)0);
  76. }
  77.  
  78. static int
  79. DECLARE2(TIFFNoEncode, TIFF*, tif, char*, method)
  80. {
  81.     const cscheme_t *c = findScheme(tif->tif_dir.td_compression);
  82.     TIFFError(tif->tif_name,
  83.         "%s %s encoding is not implemented", c->name, method);
  84.     return (-1);
  85. }
  86.  
  87. int
  88. DECLARE4(TIFFNoRowEncode, TIFF*, tif, u_char*, pp, u_long, cc, u_int, s)
  89. {
  90.     return (TIFFNoEncode(tif, "scanline"));
  91. }
  92.  
  93. int
  94. DECLARE4(TIFFNoStripEncode, TIFF*, tif, u_char*, pp, u_long, cc, u_int, s)
  95. {
  96.     return (TIFFNoEncode(tif, "strip"));
  97. }
  98.  
  99. int
  100. DECLARE4(TIFFNoTileEncode, TIFF*, tif, u_char*, pp, u_long, cc, u_int, s)
  101. {
  102.     return (TIFFNoEncode(tif, "tile"));
  103. }
  104.  
  105. static int
  106. DECLARE2(TIFFNoDecode, TIFF*, tif, char*, method)
  107. {
  108.     const cscheme_t *c = findScheme(tif->tif_dir.td_compression);
  109.     TIFFError(tif->tif_name,
  110.         "%s %s decoding is not implemented", c->name, method);
  111.     return (-1);
  112. }
  113.  
  114. int
  115. DECLARE4(TIFFNoRowDecode, TIFF*, tif, u_char*, pp, u_long, cc, u_int, s)
  116. {
  117.     return (TIFFNoDecode(tif, "scanline"));
  118. }
  119.  
  120. int
  121. DECLARE4(TIFFNoStripDecode, TIFF*, tif, u_char*, pp, u_long, cc, u_int, s)
  122. {
  123.     return (TIFFNoDecode(tif, "strip"));
  124. }
  125.  
  126. int
  127. DECLARE4(TIFFNoTileDecode, TIFF*, tif, u_char*, pp, u_long, cc, u_int, s)
  128. {
  129.     return (TIFFNoDecode(tif, "tile"));
  130. }
  131.  
  132. int
  133. DECLARE2(TIFFSetCompressionScheme, TIFF*, tif, int, scheme)
  134. {
  135.     const cscheme_t *c = findScheme(scheme);
  136.  
  137.     if (!c) {
  138.         TIFFError(tif->tif_name,
  139.             "Unknown data compression algorithm %u (0x%x)",
  140.             scheme, scheme);
  141.         return (0);
  142.     }
  143.     tif->tif_predecode = NULL;
  144.     tif->tif_decoderow = TIFFNoRowDecode;
  145.     tif->tif_decodestrip = TIFFNoStripDecode;
  146.     tif->tif_decodetile = TIFFNoTileDecode;
  147.     tif->tif_preencode = NULL;
  148.     tif->tif_postencode = NULL;
  149.     tif->tif_encoderow = TIFFNoRowEncode;
  150.     tif->tif_encodestrip = TIFFNoStripEncode;
  151.     tif->tif_encodetile = TIFFNoTileEncode;
  152.     tif->tif_close = NULL;
  153.     tif->tif_seek = NULL;
  154.     tif->tif_cleanup = NULL;
  155.     tif->tif_flags &= ~TIFF_NOBITREV;
  156.     tif->tif_options = 0;
  157.     return ((*c->init)(tif));
  158. }
  159.